 
import { EActionCode } from "framework/FSM/Action/ActionCode";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";

/**
 * 预定Action
 */
export class ActionClaim  extends ActionBaseOfCreep<IActionCMD<"claim">>
{
    public _execute(action: IActionCMD<"claim">): EActionCode 
    {
        if(action.arg.entity.pos.distance(action.arg.controller.pos)>1)
        {
            action.arg.entity.mymoveTo({pos:action.arg.controller.pos,range:1},{});
            return EActionCode.RUNNING;
        }
        if(action.arg.entity.room.controller?.my)
        {
            return EActionCode.OK;
        }
        if((!action.arg.entity.room.controller!.reservation ||action.arg.entity.room.isMyResverse()) &&  action.arg.entity.room.controller!.owner == undefined)
        {
            action.arg.entity.claimController(action.arg.controller);
            // action.arg.entity.memory={} as any;
        }
        else
        {
            action.arg.entity.attackController(action.arg.controller);
        }
        
        return  EActionCode.RUNNING;
    }
}